//
//  SingleRowPickerView.m
//  YoucApp
//
//  Created by Liam on 2/21/13.
//
//

#import "SingleRowPickerView.h"

@interface SingleRowPickerView ()

- (NSArray *)names;
- (NSArray *)values;

@end

@implementation SingleRowPickerView

@synthesize currentValue;

+ (NSArray *)names
{
	return [NSArray array];
}

+ (NSArray *)values
{
	return [NSArray array];
}

- (NSArray *)names
{
	return [[self class] names];
}

- (NSArray *)values
{
	return [[self class] values];
}

+ (NSString *)titleForValue:(id)value
{
	NSUInteger index = [[self values] indexOfObject:value];
	if (index != NSNotFound)
		return [[self names] objectAtIndex:index];
	
	return @"";
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (id)initWithValue:(id)value delegate:(id /*<UIActionSheetDelegate>*/)delegate
{
	if (self = [super init])
	{
		NSUInteger index = [[self values] indexOfObject:value];
		if (index != NSNotFound)
			[self.picker selectRow:index inComponent:0 animated:NO];
		self.delegate = delegate;
	}
	
	return self;
}

- (void)dealloc
{
	self.currentValue = nil;
	[super dealloc];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return [[self values] count];
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [[self names] objectAtIndex:row];
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
	CGSize size = [pickerView rowSizeForComponent:component];
	
    UILabel *lable = [[[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, size.width, size.height)] autorelease];
	lable.backgroundColor = [UIColor clearColor];
    lable.text = [[self names] objectAtIndex:row];
    lable.adjustsFontSizeToFitWidth = YES;
    lable.textAlignment = UITextAlignmentCenter;
    return lable;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    self.currentValue = [[self values] objectAtIndex:row];
}

@end
